package com.pmcc.core.web;

import com.pmcc.core.config.utils.AntPageRequest;
import com.pmcc.core.dto.TreeMenuNode;
import com.pmcc.core.entity.security.Authority;
import com.pmcc.core.entity.security.Dict;
import com.pmcc.core.entity.security.Employee;
import com.pmcc.core.entity.security.Role;
import com.pmcc.core.repository.AuthorityRepository;
import com.pmcc.core.repository.RoleRepository;

import com.pmcc.core.service.RoleService;
import com.pmcc.utils.AntdPage;
import com.pmcc.utils.ResultBean;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.*;

import java.util.*;
import java.util.stream.Collectors;

/**
 * Created by tomas on 18/9/4.
 */
@RestController()
@RequestMapping("api/v1/roles")
@Api(value = "RoleController" , description = "角色权限管理")
public class RoleController {

    @Autowired
    RoleService roleService;

    @ApiOperation(value = "分页查询", httpMethod = "GET", notes = "角色权限", response = ResultBean.class)
    @GetMapping(value = "queryByPage")
    public ResultBean showRole(@ApiParam(required = false, name = "分页对象", value = "分页参数，默认第一页10条数据")AntdPage antdPage,
                               @ApiParam(required = false, name="实体对象", value = "实体参数，可以是名字和调整人模糊查询")Role model) throws  Exception{
        return roleService.showLog(antdPage, model);
    }


    /**
     * 新增
     * @param remark
     *@param name
     * @param code
     * @param str
     * @param str1
     * @return
     */
    @ApiOperation(value = "新增", httpMethod = "GET", notes = "新增角色", response = ResultBean.class)
    @GetMapping(value = "addRole")//
    public ResultBean addRole(@ApiParam( name = "备注", value = "remark")String remark,
                              @ApiParam( name = "角色名字", value = "name")String name,
                              @ApiParam( name = "角色编号", value = "code")String code,
                              @ApiParam( name = "菜单keys", value = "str")String str,
                              @ApiParam( name = "菜单keys1", value = "str")String str1)throws Exception{
        return roleService.add(remark,name,code,str,str1);
    }

    /**
     * 查询角色
     * @param id
     * @return
     */
    @ApiOperation(value = "查询", httpMethod = "GET", notes = "根据id查询", response = ResultBean.class)
    @GetMapping(value = "queryById")
    public ResultBean queryById(@ApiParam(required = true,name = "id", value = "id")String id){
        return roleService.findById(id);
    }

    /**
     * 修改
     * @param map
     * @return
     */
    @ApiOperation(value = "修改保存", httpMethod="PUT", notes = "保存修改角色信息", response = ResultBean.class)
    @PostMapping(value= "updateById")
    public ResultBean edit(@ApiParam(required =true, name ="角色信息", value ="必须传输id")@RequestBody Map map) {
        return roleService.update(map);
    }

    /**
     * 删除
     * @param id
     * @return
     */
    @ApiOperation(value = "id", httpMethod="GET", notes = "假删除角色信息", response = ResultBean.class)
    @GetMapping("deleteById")
    public ResultBean delete(@ApiParam(required =true, name ="假除角色信息", value ="id")String id) {
        return roleService.deleteById(id,1);
    }

    /**
     * 查询所有角色
     */
    @ApiOperation(value = "查询", httpMethod = "GET", notes = "查询所有角色", response = ResultBean.class)
    @GetMapping(value = "findAll")
    public ResultBean findAll(){
        return roleService.findAll();
    }
}
